﻿@{
    Layout = null;
    MICZ.CodeBuilder.ViewModels.WorkContent WorkContent = ViewBag.WorkContent;
}
<script src="@WorkContent.ThemePath/js/jquery-3.4.1.min.js"></script>
<link href="@WorkContent.ThemePath/layui/css/layui.css" rel="stylesheet" />
<script src="@WorkContent.ThemePath/layui/layui.js"></script>
<script src="@WorkContent.ThemePath/bais.js"></script>

<blockquote class="layui-elem-quote">@ViewData["title"]</blockquote>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="Add">添加</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use('table', function () {
        var table = layui.table;
        var tableData = {};
        if (getQueryVariable("TITLEID") != "")
            tableData.titleid = getQueryVariable("TITLEID");

        table.render({
            elem: '#test'
            , url: '/ManageAPI/Answer/GetListEx'
            , toolbar: '#toolbarDemo'
            , method: 'POST'
            , title: '答案信息'
            , headers: header
            , where: tableData
            , cols: [[
                { type: 'checkbox', fixed: 'left' }
                , { field: 'ANSWERID', title: '答案ID', fixed: 'left', width: 120, unresize: false, sort: true }
                //, {
                //    field: 'ICO', title: '栏目图标', align: "left", width: 100, sort: false,
                //    templet: function (d) { return '<div><img src=' + d.ICO + '></div>' }
                //}
                , { field: 'ANSWERCODE', title: '答案选项', width: 120 }
                , { field: 'ANSWERNAME', title: '答案', width: 120 }
                , {
                    field: 'ISANSWER', title: '是否是正确答案', width: 150, templet: function (res) {
                        return (res.ISANSWER == 1? '<em>是</em>' : '<em>否</em>')
                    }
                }
                , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 160 }
            ]], parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.Status, //解析接口状态
                    "msg": res.Msg, //解析提示文本
                    "count": res.TotalCount, //解析数据长度
                    "data": res.Data.Obj.DataList //解析数据列表
                };
            }
            , response: {
                 statusCode: 1 //规定成功的状态码，默认：0
            }
            , page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case "Add":
                    console.log('Add');
                layer.open({
                    type: 2
                    ,area:['90%','90%']
                    , title:'@ViewData["title"]'
                    , offset: 'auto'
                    , resize: false
                    , shadeClose: true
                    , content: '/Manage/Answer/Edit?Type=Add&titleid=' + getQueryVariable("TITLEID")
                    , end: function () {//无论是确认还是取消，只要层被销毁了，end都会执行，不携带任何参数。layer.open关闭事件
                        location.reload();　　//layer.open关闭刷新
                    }
                });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'edit') {
                console.log('edit' + (obj.data).ID);
                layer.open({
                    type: 2
                    , area: [1000, 600]
                    , title: '@ViewData["title"]'
                    , offset: 'auto'
                    , resize: false
                    , shadeClose: true
                    , content: '/Manage/Answer/Edit?Type=Edit&ID=' + (obj.data).ANSWERID + '&titleid=' + getQueryVariable("TITLEID") //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    , end: function () {//无论是确认还是取消，只要层被销毁了，end都会执行，不携带任何参数。layer.open关闭事件
                        location.reload();　　//layer.open关闭刷新
                    }
                });
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    $.ajax({
                        type: "GET",
                        url: "/ManageAPI/Answer/Del?ID=" + (obj.data).ANSWERID ,
                        //data: { "ID": (obj.data).ID },
                        dataType: "json",
                        headers: header,
                        success: function (data) {
                            location.reload();
                        },
                        error: function (data) {
                            layer.alert("提交出现了错误！");
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>